import React, {Component} from 'react';
import './Cursor.css';

export default class Cursor extends Component {
    constructor(props) {
        super(props);
        this._isReRenderingCursor = false;
        this.state = {
            shouldRender: true,
        };
    }

    componentDidUpdate() {
        if (this._isReRenderingCursor) {
            return;
        }
        this._reRenderCursor();
    }

    _reRenderCursor() {
        this._isReRenderingCursor = true;
        this.setState({shouldRender: false}, () => {
            this.setState({shouldRender: true}, () => {
                this._isReRenderingCursor = false;
            });
        });
    }

    render() {
        if (this.state.shouldRender) {
            return (
                <span className={`Cursor Cursor--blinking`}>
          |
        </span>
            );
        }
        return null;
    }
}
